import unittest
from unittest.mock import patch

from pyecharts import options as opts
from pyecharts.charts import Radar

v1 = [(4300, 10000, 28000, 35000, 50000, 19000)]
v2 = [(5000, 14000, 28000, 31000, 42000, 21000)]


class TestRadarChart(unittest.TestCase):
    @patch("pyecharts.render.engine.write_utf8_html_file")
    def test_radar_base(self, fake_writer):
        c = (
            Radar()
            .add_schema(
                schema=[
                    opts.RadarIndicatorItem(name="销售", max_=6500),
                    opts.RadarIndicatorItem(name="管理", max_=16000),
                    opts.RadarIndicatorItem(name="信息技术", max_=30000),
                    opts.RadarIndicatorItem(name="客服", max_=38000),
                    opts.RadarIndicatorItem(name="研发", max_=52000),
                    opts.RadarIndicatorItem(name="市场", max_=25000),
                ]
            )
            .add("预算分配", v1)
            .add("实际开销", v2)
            .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        )
        c.render()
        _, content = fake_writer.call_args[0]
        self.assertEqual(c.theme, "white")
        self.assertEqual(c.renderer, "canvas")

    @patch("pyecharts.render.engine.write_utf8_html_file")
    def test_radar_item_base(self, fake_writer):
        series_names = ["预算分配", "实际开销"]
        series_data = [
            [4300, 10000, 28000, 35000, 50000, 19000],
            [5000, 14000, 28000, 31000, 42000, 21000],
        ]
        radar_item = [
            opts.RadarItem(name=d[0], value=d[1])
            for d in list(zip(series_names, series_data))
        ]

        c = (
            Radar()
            .add_schema(
                schema=[
                    opts.RadarIndicatorItem(name="销售", max_=6500),
                    opts.RadarIndicatorItem(name="管理", max_=16000),
                    opts.RadarIndicatorItem(name="信息技术", max_=30000),
                    opts.RadarIndicatorItem(name="客服", max_=38000),
                    opts.RadarIndicatorItem(name="研发", max_=52000),
                    opts.RadarIndicatorItem(name="市场", max_=25000),
                ]
            )
            .add("", radar_item)
            .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
            .set_global_opts(title_opts=opts.TitleOpts(title="Radar-基本示例"))
        )
        c.render()
        _, content = fake_writer.call_args[0]
        self.assertEqual(c.theme, "white")
        self.assertEqual(c.renderer, "canvas")

    @patch("pyecharts.render.engine.write_utf8_html_file")
    def test_radar_options(self, fake_writer):
        c = (
            Radar()
            .add_schema(
                schema=[
                    opts.RadarIndicatorItem(name="销售", max_=6500),
                    opts.RadarIndicatorItem(name="管理", max_=16000),
                    opts.RadarIndicatorItem(name="信息技术", max_=30000),
                    opts.RadarIndicatorItem(name="客服", max_=38000),
                    opts.RadarIndicatorItem(name="研发", max_=52000),
                    opts.RadarIndicatorItem(name="市场", max_=25000),
                ],
                radiusaxis_opts=opts.RadiusAxisOpts(),
                angleaxis_opts=opts.AngleAxisOpts(),
                polar_opts=opts.PolarOpts(),
            )
            .add("预算分配", v1)
            .add("实际开销", v2)
            .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        )
        c.render()
        _, content = fake_writer.call_args[0]
        self.assertIn("radiusAxis", content)
        self.assertIn("angleAxis", content)
        self.assertIn("polar", content)
